package com.example.pattern.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 子节点：组合部门
 *
 * @author FM_南风
 * @date 2024/7/3 13:56
 */
public class CompositeDepartment implements Department{
    private String name;
    private List<Department> departments = new ArrayList<>();

    public CompositeDepartment(String name) {
        this.name = name;
    }

    public void addDepartment(Department department) {
        departments.add(department);
    }

    public void removeDepartment(Department department) {
        departments.remove(department);
    }

    @Override
    public void printDepartmentName() {
        System.out.println("Department: " + name);
        for (Department department : departments) {
            department.printDepartmentName();
        }
    }
}
